﻿using System;
using log4net;
using System.Windows.Threading;

namespace FLMScan.Exception
{
    class UnhandledExceptionHandler
    {
        private static UnhandledExceptionHandler instance;
        private ILog logger;

        UnhandledExceptionHandler()
        {
            logger = LogManager.GetLogger(typeof(UnhandledExceptionHandler));
        }

        public static UnhandledExceptionHandler Instance()
        {
            if (instance == null)
                instance = new UnhandledExceptionHandler();

            return instance;
        }

        public void HandleException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            e.Handled = true;
            logger.Error("Unhandled Exception caught: " + e.Exception);
        }
         
        public void HandleException(object sender, UnhandledExceptionEventArgs e)
        {
            logger.Error("Unhandled Exception caught: " + e.ExceptionObject);
        }
    }
}
